package com.yango.teach.controller.front;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yango.commonutil.result.Result;
import com.yango.teach.entity.Course;
import com.yango.teach.entity.Teacher;
import com.yango.teach.entity.vo.subject.OneSubjectVo;
import com.yango.teach.service.CourseService;
import com.yango.teach.service.SubjectService;
import com.yango.teach.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.xml.crypto.Data;
import java.util.List;

/**
 * <p>
 * 前台网站数据 前端控制器
 * </p>
 *
 * @author LiDingYin
 * @since 2021-07-24
 */
@Api(description = "前台网站数据 前端控制器")
@RestController
@RequestMapping("/teach/index")
public class IndexController {

    @Autowired
    private CourseService courseService;
    @Autowired
    private TeacherService teacherService;

    //查询前台首页数据
    @ApiOperation(value = "查询前台首页数据")
    @GetMapping("/getFrontData")
    public Result getFrontData() {
        //查询最新前8门课程
        QueryWrapper<Course> courseQueryWrapper = new QueryWrapper<>();//条件对象
        courseQueryWrapper.orderByDesc("buy_count");//根据id降序排序
        courseQueryWrapper.last("limit 8");//拼接sql
        List<Course> courseList = courseService.list(courseQueryWrapper);//查询

        //查询前4位讲师
        QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();//条件对象
        teacherQueryWrapper.orderByDesc("id");//根据id降序排序
        teacherQueryWrapper.last("limit 4");//拼接sql
        List<Teacher> teacherList = teacherService.list(teacherQueryWrapper);//查询
        //返回
        return Result.ok().data("courseList", courseList).data("teacherList", teacherList);
    }

}

